@(issue: gitbucket.core.model.Issue,
  reopenable: Boolean,
  isEditable: Boolean,
  isManageable: Boolean,
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@if(isEditable){
  <form method="POST" validate="true" autocomplete="off">
    <div class="panel panel-default issue-comment-box">
      <div class="panel-body">
        @gitbucket.core.helper.html.preview(
          repository         = repository,
          content            = "",
          enableWikiLink     = false,
          enableRefsLink     = true,
          enableLineBreaks   = true,
          enableTaskList     = true,
          hasWritePermission = isEditable,
          completionContext  = "issues",
          style              = "",
          elastic            = true,
          tabIndex           = 1
        )
        <div class="text-right">
          <input type="hidden" name="issueId" value="@issue.issueId"/>
          @if((reopenable || !issue.closed) && (isManageable || issue.openedUserName == context.loginAccount.get.userName)){
            <input type="hidden" id="action" name="action" value="comment"/>
            <div class="btn-group dropup">
              <input type="submit" class="btn btn-success" tabindex="2" formaction="@helpers.url(repository)/issue_comments/new" value="Comment" id="submit-button"/>
              <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="Select method">
                <span class="caret"></span>
              </button>
            <ul class="dropdown-menu dropdown-menu-right">
              <li><a id="menu-comment">Comment</a></li>
              <li><a id="menu-x-and-comment">@{if(issue.closed) "Reopen" else "Close"} and comment</a></li>
            </ul>
            </div>
          } else {
            <input type="submit" class="btn btn-success" tabindex="2" formaction="@helpers.url(repository)/issue_comments/new" value="Comment"/>
          }
        </div>
      </div>
    </div>
  </form>
}
<script>
$(function(){
  $('#menu-comment').click(function(){
    $('#submit-button').attr('value', 'Comment').attr('formaction', '@helpers.url(repository)/issue_comments/new');
    $('#action').val('comment');
  });
  $('#menu-x-and-comment').click(function(){
    $('#submit-button').attr('value', '@{if(issue.closed) "Reopen" else "Close"} and comment').attr('formaction', '@helpers.url(repository)/issue_comments/state');
    $('#action').val('@{if(issue.closed) "reopen" else "close"}');
  });
});
</script>
